****************
*** PANEL A ****
****************
clear all 
set more off
cd "/Users/yasenov/Dropbox/mariel_boatlift/jhr_version/jhr_figures"
global folder /Users/yasenov/Dropbox/mariel_boatlift/revision_version/revision_data/
set scheme s1color

use $folder/aux_may-org.dta

keep if age >= 19 & age <= 65
keep if cuban == 0
keep if low_skilled == 1
drop if (ftpt79 == 0 & year <= 1988) | (ftpt89 ==1 & year > 1988) 
keep if classer == 1 | classer == 2 
keep if male == 1

collapse (mean) logearnwke [pw=earnwt], by(year smsarank)
merge 1:1 year smsa using $folder/msa_controls_may-org.dta, nogenerate
xtset smsa year   

local controls logearnwke low_skilled hisp manuf
synth logearnwke `controls', trunit(26) trperiod(1980) nested keep(fig4a.dta, replace)

use fig4a, clear
rename (_time _Y_treated _Y_synthetic) (year miami synthetic)
keep if year != .
twoway (line miami year, lcolor(black) lpattern(solid)) ///
	(line synthetic year, lcolor(black) lpattern(dash)), ///
	xline(1979, lcolor(black) lpattern(dash)) ///
	xtitle("") ///
	ytitle("") ///
	legend(label(1 "Miami") label(2 "Synthetic Miami")) ///
	subtitle("Non-Hispanic Men") ///
	xlabel(1973 "1973" 1975 "75" 1977 "77" 1979 `""79" "Pre""' 1981 `""81" "Post""' 1983 "83" 1985 "85" 1987 "87" 1989 "89" 1991 "91") ///
	xscale(range(1972 1992)) ///
	ylabel(5(.1)5.5) ///
	yscale(range(5 5.5)) ///
	text(5.5 1990.8 "Panel A")  nodraw  plotregion(lwidth(none))

graph copy one, replace

****************
*** PANEL B ****
****************
clear
use $folder/aux_may-org.dta

keep if age >= 19 & age <= 65
keep if cuban == 0
keep if low_skilled == 1
drop if (ftpt79 == 0 & year <= 1988) | (ftpt89 ==1 & year > 1988) 
keep if classer == 1 | classer == 2 
keep if male == 0

collapse (mean) logearnwke [pw=earnwt], by(year smsarank)
merge 1:1 year smsa using $folder/msa_controls_may-org.dta, nogenerate
xtset smsa year   

local controls logearnwke(1979) logearnwke low_skilled hisp manuf
synth logearnwke `controls', trunit(26) trperiod(1980) nested keep(fig4b.dta, replace)

use fig4b, clear
rename (_time _Y_treated _Y_synthetic) (year miami synthetic)
keep if year != .
twoway (line miami year if year < 1991, lcolor(black) lpattern(solid)) ///
	(line synthetic year if year < 1991, lcolor(black) lpattern(dash)), ///
	xline(1979, lcolor(black) lpattern(dash)) ///
	xtitle("") ///
	ytitle("") ///
	legend(label(1 "Miami") label(2 "Synthetic Miami")) ///
	subtitle("Women") ///
	xlabel(1973 "1973" 1975 "75" 1977 "77" 1979 `""79" "Pre""' 1981 `""81" "Post""' 1983 "83" 1985 "85" 1987 "87" 1989 "89" 1991 "91") ///
	xscale(range(1972 1992)) ///
	ylabel(4.6(.1)5.1) ///
	yscale(range(4.6 5.1)) ///
	text(5.1 1990.8 "Panel B")  nodraw  plotregion(lwidth(none))

graph copy two, replace

****************
*** PANEL C ****
****************
clear
use $folder/aux_may-org.dta

keep if age >= 19 & age <= 65
keep if cuban == 0
keep if low_skilled == 1
drop if (ftpt79 == 0 & year <= 1988) | (ftpt89 ==1 & year > 1988) 
keep if classer == 1 | classer == 2 
keep if hisp == 1

collapse (mean) logearnwke [pw=earnwt], by(year smsarank)
merge 1:1 year smsa using $folder/msa_controls_may-org.dta, nogenerate
xtset smsa year 
  
drop if logearnwke == . 
bysort smsa: drop if _N != 19 // maybe can improve this

local controls low_skilled hisp manuf
synth logearnwke `controls', trunit(26) trperiod(1980) nested keep(fig4c.dta, replace) fig

use fig4c, clear
rename (_time _Y_treated _Y_synthetic) (year miami synthetic)
keep if year != .
scalar a = synthetic[7]-miami[7]
replace synthetic = synthetic - a
twoway (line miami year, lcolor(black) lpattern(solid)) ///
	(line synthetic year, lcolor(black) lpattern(dash)), ///
	xline(1979, lcolor(black) lpattern(dash)) ///
	xtitle("") ///
	ytitle("") ///
	legend(label(1 "Miami") label(2 "Synthetic Miami")) ///
	subtitle("Hispanics") ///
	xlabel(1973 "1973" 1975 "75" 1977 "77" 1979 `""79" "Pre""' 1981 `""81" "Post""' 1983 "83" 1985 "85" 1987 "87" 1989 "89" 1991 "91") ///
	xscale(range(1972 1992)) ///
	text(5.5 1990.8 "Panel C")  nodraw  plotregion(lwidth(none))
	
graph copy three, replace

****************
*** PANEL D ****
****************
clear
use $folder/aux_may-org.dta

keep if age >= 19 & age <= 65
keep if cuban == 0
keep if low_skilled == 1
drop if (ftpt79 == 0 & year <= 1988) | (ftpt89 ==1 & year > 1988) 
keep if classer == 1 | classer == 2 
keep if black == 1

collapse (mean) logearnwke [pw=earnwt], by(year smsarank)
merge 1:1 year smsa using $folder/msa_controls_may-org.dta, nogenerate
xtset smsa year   

gen aux = logearnwke == .
bysort smsa: drop if aux == 1
bysort smsa: drop if _N != 19

local controls logearnwke(1979) logearnwke(1975) logearnwke(1977) low_skilled hisp manuf
synth logearnwke `controls', trunit(26) trperiod(1980) nested keep(fig4d.dta, replace)

use fig4d, clear
rename (_time _Y_treated _Y_synthetic) (year miami synthetic)
keep if year != .
twoway (line miami year, lcolor(black) lpattern(solid)) ///
	(line synthetic year, lcolor(black) lpattern(dash)), ///
	xline(1979, lcolor(black) lpattern(dash)) ///
	xtitle("") ///
	ytitle("") ///
	legend(label(1 "Miami") label(2 "Synthetic Miami") size(small)) ///
	subtitle("African-American") ///
	xlabel(1973 "1973" 1975 "75" 1977 "77" 1979 `""79" "Pre""' 1981 `""81" "Post""' 1983 "83" 1985 "85" 1987 "87" 1989 "89" 1991 "91") ///
	xscale(range(1972 1992))  ///
	ylabel(4.8(.1)5.3) ///
	yscale(range(4.8 5.3)) ///
	text(5.3 1990.8 "Panel D")  nodraw  plotregion(lwidth(none))

graph copy four, replace

grc1leg one two three four, imargin(vsmall) legendfrom(four)	
graph export "jhr_fig4.pdf", replace
